package com.sphd.Restaurant.fragments;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.sphd.Restaurant.R;
import com.sphd.Restaurant.activity.OrderActivity;
import com.sphd.Restaurant.adapters.DiesAdapter;
import com.sphd.Restaurant.base.BaseFragment;
import com.sphd.Restaurant.infos.Dishes;
import com.sphd.Restaurant.infos.RestaurantInfo;
import com.sphd.Restaurant.interfFace.TrueMoneyCallBack;
import com.sphd.Restaurant.utils.Constants;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Hu on 2016/10/11.
 */

public class OrderItemFragment extends BaseFragment {
    @BindView(R.id.my_recy)
    RecyclerView myRecy;
    List<Dishes> dishes;
    Bundle bundle;
    RestaurantInfo restaurantInfo;
    DiesAdapter diesAdapter;
    private TrueMoneyCallBack addMoneyCallBack;//点击+的监听
    private TrueMoneyCallBack removeMoneyCallBack;//点击-的监听
    @Override
    public int getLayout() {
        return R.layout.fragment_order_item;
    }

    @Override
    public void initViews(View rootView) {
        ButterKnife.bind(this, rootView);
        bundle = getArguments();//从activity传过来的Bundle
        dishes = (List<Dishes>) bundle.getSerializable(Constants.DISHES);
        restaurantInfo = (RestaurantInfo) bundle.getSerializable(Constants.RESTAURANT);
        setGridRecy(myRecy);
        initAdapter();
    }

    private void initAdapter() {
        diesAdapter = new DiesAdapter(dishes,addMoneyCallBack,removeMoneyCallBack,restaurantInfo);
        myRecy.setAdapter(diesAdapter);
    }


    public void setaddCallBack(OrderActivity.AddCallback addCallback) {
        this.addMoneyCallBack=addCallback;
    }

    public void setRemoveCallBack(OrderActivity.RemoveCallBack removeCallBack) {
        this.removeMoneyCallBack=removeCallBack;
    }
}
